<!--综合管理-->
<template>
  <div class="m-view-masterMenu m-window">
    <div class="m-module" v-for="(item, index) in menu" :key="index">
      <div class="m-title" v-if="item.list.length>0">{{ item.title }}</div>
      <ul>
        <li
          v-for="(list, serial) in item.list"
          :key="serial"
          @click="addTab(list)"
          :class="{ 'm-completed': list.completed }"
        >
          <i :class="'iconfont icon-' + list.name"></i>
          <span>{{ list.cName }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import utils from "@/public/utils";
import authorize from "@/public/authorize";

export default {
  data() {
    return {
      menu:[],
      initMenu: [
        {
          title: "短融产品",
          list: [
            {
              cName: "金单宝",
              name: "orderfinance",
              completed: false,
            },
            {
              cName: "金货宝",
              name: "deliveryfinance",
              completed: false,
            },
            {
              cName: "天进宝",
              name: "applyShort",
              completed: false,
            },
          ],
        },
        {
          title: "长融产品",
          list: [
            {
              cName: "月有钱",
              name: "applyLong",
              completed: false,
            },
          ],
        },
        {
          title: "我的申请",
          list: [
            {
              cName: "我的申请",
              name: "applyList",
              completed: false,
            },
          ],
        },
        {
          title: "产品介绍",
          list: [
            {
              cName: "产品介绍",
              name: "productionIntroduce",
              completed: false,
            },
          ],
        },
      ],
    };
  },
  props: {
    addTab: {
      type: Function,
    },
  },
  methods: {
    getMenuDetails() {
      let parentId = utils.getMenuId("menuId"); // 菜单ID
      let activeMenu = [];
      authorize.getMenuAuth(parentId).then((res) => {
        if (Array.isArray(res) && res.length > 0) {
          this.initMenu.forEach((menu, index) => {
            activeMenu.push({
              title: menu.title,
              list: [],
            });
            res.forEach((item) => {
              menu.list.forEach((el) => {
                if (el.name == item.code) {
                  activeMenu[index].list.push({
                    name: item.code,
                    cName: item.name,
                    completed: true,
                  });
                }
              });
            });
          });
          this.menu = activeMenu;
        }
      });
    },
  },
  components: {},
  beforeMount() {
    this.getMenuDetails();
  },
};
</script>

<style></style>
